import 'package:flutter/foundation.dart';
import 'dart:io';
import 'config_loader.dart';

class AppConfig {
  static final ConfigLoader _config = ConfigLoader();

  /// 初始化配置
  static Future<void> init() async {
    await _config.init();
  }

  /// 获取API服务器URL
  static String get apiServerUrl {
    if (!_config.isInitialized) {
      throw StateError('AppConfig未初始化，请先调用AppConfig.init()');
    }
    return _config.apiBaseUrl;
  }

  /// 获取API配置
  static Map<String, dynamic> get apiConfig {
    if (!_config.isInitialized) {
      throw StateError('AppConfig未初始化，请先调用AppConfig.init()');
    }
    return _config.apiConfig;
  }

  /// 获取当前环境
  static String get environment {
    if (!_config.isInitialized) {
      throw StateError('AppConfig未初始化，请先调用AppConfig.init()');
    }
    return _config.environment;
  }

  /// 获取API超时设置
  static Duration get apiTimeout {
    if (!_config.isInitialized) {
      throw StateError('AppConfig未初始化，请先调用AppConfig.init()');
    }
    return Duration(milliseconds: _config.getTimeout('api'));
  }

  /// 获取API重试次数
  static int get apiRetries {
    if (!_config.isInitialized) {
      throw StateError('AppConfig未初始化，请先调用AppConfig.init()');
    }
    return _config.getRetries('api');
  }

  /// 获取缓存时间
  static Duration get cacheDuration {
    if (!_config.isInitialized) {
      throw StateError('AppConfig未初始化，请先调用AppConfig.init()');
    }
    return Duration(seconds: _config.cacheDuration);
  }

  /// 获取最大上传大小
  static int get maxUploadSize {
    if (!_config.isInitialized) {
      throw StateError('AppConfig未初始化，请先调用AppConfig.init()');
    }
    return _config.maxUploadSize;
  }

  /// 是否启用调试日志
  static bool get debugLogging {
    if (!_config.isInitialized) {
      throw StateError('AppConfig未初始化，请先调用AppConfig.init()');
    }
    return _config.debugLogging;
  }

  /// 是否启用缓存
  static bool get cacheEnabled {
    if (!_config.isInitialized) {
      throw StateError('AppConfig未初始化，请先调用AppConfig.init()');
    }
    return _config.cacheEnabled;
  }
}
